package com.zq.rabbitmq.servcie;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


//direct交换器
@Service
public class DirectSenderServiceImpl implements SenderService{
    private static final Logger logger=LoggerFactory.getLogger(DirectSenderServiceImpl.class);

    @Autowired
    private AmqpTemplate amqpTemplate;
    @Autowired
    private ObjectMapper objectMapper;


    public void sendbyte(byte[] bytes){
        amqpTemplate.convertAndSend("directEx", "queue01", new String(bytes));
    }

    public void sendString(String str){
        amqpTemplate.convertAndSend("directEx", "queue01", str);
    }

    public void sendObject(Object object) throws JsonProcessingException {
        String jsonString = objectMapper.writeValueAsString(object);

        amqpTemplate.convertAndSend("directEx", "queue01", jsonString);
    }
}
